function http ({ header, url, method, data, params }) {
	return new Promise ((resolve, reject) => {
		if (method == "post" && params) {
			if (url.indexOf("?") <= 0) {
				url = url + "?"
			}
			let paramStr = ""
			for (let p in params) {
				paramStr = paramStr + `&${p}=${params[p]}`
			}
			paramStr = paramStr.substring(1)
			url = url + paramStr
		}
		uni.request({
			header, url, method, data,
			timeout: 30000,
			success (response) {
				if (response.statusCode == 200) {
					resolve(response.data)
				} else {
					resolve({ code: response.statusCode })
				}
			},
			fail (e) {
				console.error(e)
				resolve({ code: 400, msg: e.errMsg || "请求失败" })
			}
		})
	})
}

export default http